home *** CD-ROM | disk | FTP | other *** search
/ Amiga Aktuell / Amiga Aktuell.iso / amiga-aktuell / net tools / usefull / uuclean04 / uuclean04.c < prev    next >
C/C++ Source or Header  |  1996-09-05  |  4KB  |  152 lines

  1. /* uuclean.c ... remove extraneous stuff from captured
  2.    uuencoded files 07 Nov 1995 */
  3.  
  4. #include <stdio.h>
  5. #define INCHARS 128
  6. #define MAX 6
  7.  
  8. main(int argc,char *argv[])
  9.  
  10. {
  11.    FILE *infile;
  12.    FILE *outfile;
  13.    char instring[INCHARS];
  14.    char oldstring[INCHARS];
  15.    char teststr[MAX];
  16.    char testend[MAX];
  17.    char testsize[MAX];
  18.    char oneback[INCHARS];
  19.    char twoback[INCHARS];
  20.    char threeback[INCHARS];
  21.    char current[INCHARS];
  22.    static char beginstr[] =  "begin";
  23.    static char beginc[] = ":";
  24.    static char beging[] = ">";
  25.    static char space[] = " ";
  26.    static char endstr[] = "end";
  27.    static char sizestr[] ="size";
  28.    static char mstring[] = "M";
  29.    static char version[] = "$VER: uuclean 0.4 (10.08.1996)";
  30.    int i,j;
  31.    int start = 1;
  32.    int end = 1;
  33.    int size = 1;
  34.    int write = 0;
  35.    
  36.    if (argc != 3)
  37.    {
  38.       printf ("\n UUCLEAN by rdavis@nyx.cs.du.edu (Robert Davis), version 0.4");
  39.       printf ("\n Usage: %s INPUT OUTPUT \n Where INPUT and OUTPUT are filenames\n"
  40.       ,argv[0]);
  41.       exit(1);
  42.    }  
  43.  
  44.    if ((infile = fopen(argv[1],"r")) == NULL)
  45.    {
  46.       printf ("\n Cannot open %s\n",argv[1]);
  47.       exit(1);
  48.    }
  49.    
  50.    if (( outfile = fopen(argv[2],"w")) == NULL)
  51.    {
  52.       printf ("\n Unable to open output file %s\n",argv[2]);
  53.       exit(2);
  54.    }
  55.    printf ("\n Working ... CTRL C exits\n");
  56.    
  57.    do   
  58.    {  fgets (instring,INCHARS,infile); /* get a line from the file */
  59.       i = j = strlen(instring);
  60.    
  61.       /* check for a quote indicator */
  62.       if ((*instring == *beginc) || (*instring == *beging))
  63.          {for (i=0;i<strlen(instring);i++)
  64.             (instring[i] = instring[i+1]);}
  65.   
  66.       if (*instring == *space)
  67.          { for (i=0;i<strlen(instring);i++)
  68.             (instring[i] = instring[i+1]); }
  69.             
  70.       if (i != j)
  71.           instring[i] = 0x00;
  72.       else (instring[j] = 0x00);
  73.                  
  74.       /* find   begin  */
  75.       for (i=0;i<5;i++)
  76.          { teststr[i] = instring[i]; }
  77.       teststr[i] = 0x00; /* put null at end of string */ 
  78.  
  79.       start = (strcmp(teststr,beginstr));  /* true if cmp == 0 */
  80.  
  81.    } while (start != 0);
  82.    
  83.    /* printf ("\n Found 'begin' %s\n",instring); */
  84.           
  85.       fputs (instring,outfile); /*write the 'begin' line */
  86.       
  87.       write = 1; /* flag */       
  88.    
  89.    while (fgets (instring,INCHARS,infile) != NULL)
  90.    {      
  91.       i = j = strlen(instring);
  92.    
  93.       /* check for a quote indicator */
  94.       if ((*instring == *beginc) || (*instring == *beging))
  95.          {for (i=0;i<strlen(instring);i++)
  96.             (instring[i] = instring[i+1]);}
  97.   
  98.       if (*instring == *space) /* maybe a following space */
  99.          { for (i=0;i<strlen(instring);i++)
  100.             (instring[i] = instring[i+1]); }
  101.             
  102.       if (i != j)
  103.           instring[i] = 0x00;
  104.       else (instring[j] = 0x00);
  105.                        
  106.       strcpy (threeback,twoback);
  107.       strcpy (twoback,oneback);
  108.       strcpy (oneback,current);
  109.       strcpy (current,instring);
  110.                      
  111.       /* look for end */
  112.       for (i=0;i<3;i++)
  113.          { testend[i] = instring[i]; }
  114.       testend[i] = 0x00; /* again add null at end of string */
  115.       
  116.       /* look for size */
  117.       for (i=0;i<4;i++)
  118.          { testsize[i] = instring[i]; }
  119.       testsize[i] = 0x00; /* add null to allow string comparison */
  120.                
  121.       end = (strcmp(endstr,testend));
  122.       size = (strcmp(sizestr,testsize));
  123.                 
  124.       if (size == 0)
  125.         { fputs (instring,outfile);  /* writes the 'size xxxx' line */ 
  126.           write = 0;
  127.           break;}
  128.       
  129.       if (end == 0)
  130.         { fputs (twoback,outfile); /* this might be a problem with some files, */
  131.                  /* if the last full line of the file is exactly xx characters */
  132.                             /* so that there is no partial line before the  '' */
  133.           fputs (oneback,outfile);
  134.           fputs (instring,outfile); }
  135.           /* fputs the last lines of the uuencoded file */
  136.         
  137.       /* compare then copy the new string to the old string */
  138.       
  139.       if ((strcmp (oldstring,instring) != 0) &&
  140.           (strcmp (twoback,instring) != 0) &&
  141.           (strcmp (threeback,instring) != 0))
  142.         {         
  143.          if ((*instring == *mstring)&&(write == 1)) /* if first char in line is M */
  144.             {fputs (instring,outfile);
  145.                strcpy (oldstring,instring); }            
  146.         }
  147.    }   
  148.    fclose (outfile);
  149.    fclose (infile);
  150.    printf ("\n Done.\n");
  151. }
  152.